//
//  PrivacyPolicyViewController.m
//  SnapCAD
//
//  Created by Developer on 2025/1/27.
//

#import "PrivacyPolicyViewController.h"
#import "Masonry.h"

@interface PrivacyPolicyViewController ()

@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UIButton *backButton;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UILabel *contentLabel;

@end

@implementation PrivacyPolicyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self setupConstraints];
    [self loadPrivacyPolicyContent];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

- (void)setupUI {
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupHeader];
    [self setupScrollView];
}

- (void)setupHeader {
    // 头部视图
    self.headerView = [[UIView alloc] init];
    self.headerView.backgroundColor = [UIColor whiteColor];
    
    // 添加阴影
    self.headerView.layer.shadowColor = [UIColor blackColor].CGColor;
    self.headerView.layer.shadowOffset = CGSizeMake(0, 2);
    self.headerView.layer.shadowOpacity = 0.1;
    self.headerView.layer.shadowRadius = 4;
    
    self.headerView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:self.headerView];
    
    // 返回按钮
    self.backButton = [UIButton buttonWithType:UIButtonTypeSystem];
    [self.backButton setImage:[UIImage systemImageNamed:@"chevron.left"] forState:UIControlStateNormal];
    self.backButton.tintColor = [UIColor colorWithRed:0.40 green:0.49 blue:0.93 alpha:1.0];
    [self.backButton addTarget:self action:@selector(backButtonTapped) forControlEvents:UIControlEventTouchUpInside];
    self.backButton.translatesAutoresizingMaskIntoConstraints = NO;
    [self.headerView addSubview:self.backButton];
    
    // 标题标签
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.text = @"Privacy Policy";
    self.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [self.headerView addSubview:self.titleLabel];
}

- (void)setupScrollView {
    // 滚动视图
    self.scrollView = [[UIScrollView alloc] init];
    self.scrollView.backgroundColor = [UIColor whiteColor];
    self.scrollView.showsVerticalScrollIndicator = YES;
    self.scrollView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:self.scrollView];
    
    // 内容标签
    self.contentLabel = [[UILabel alloc] init];
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.font = [UIFont systemFontOfSize:14];
    self.contentLabel.textColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1.0];
    self.contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.contentLabel.translatesAutoresizingMaskIntoConstraints = NO;
    [self.scrollView addSubview:self.contentLabel];
}

- (void)setupConstraints {
    // 头部视图约束
    [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.height.equalTo(@88);
    }];
    
    // 返回按钮约束
    [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerView).offset(6);
        make.bottom.equalTo(self.headerView).offset(-10);
        make.size.mas_equalTo(CGSizeMake(44, 44));
    }];
    
    // 标题标签约束
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.headerView);
        make.centerY.equalTo(self.backButton);
    }];
    
    // 滚动视图约束
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    
    // 内容标签约束
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollView).offset(20);
        make.left.equalTo(self.scrollView).offset(20);
        make.right.equalTo(self.scrollView).offset(-20);
        make.bottom.equalTo(self.scrollView).offset(-20);
        make.width.equalTo(self.scrollView).offset(-40);
    }];
}

- (void)loadPrivacyPolicyContent {
    NSString *privacyPolicy = @"PRIVACY POLICY\n\nLast updated: January 27, 2025\n\n1. INFORMATION WE COLLECT\n\nWe collect information you provide directly to us, such as when you create an account, use our services, or contact us for support.\n\n• Personal Information: Name, email address, and other contact information\n• Usage Data: Information about how you use our application and services\n• Device Information: Information about your device, including device type, operating system, and unique device identifiers\n• File Data: CAD files and related metadata that you upload or create using our services\n\n2. HOW WE USE YOUR INFORMATION\n\nWe use the information we collect to:\n\n• Provide, maintain, and improve our services\n• Process transactions and send related information\n• Send technical notices, updates, security alerts, and support messages\n• Respond to your comments, questions, and customer service requests\n• Monitor and analyze trends, usage, and activities in connection with our services\n• Detect, investigate, and prevent fraudulent transactions and other illegal activities\n\n3. INFORMATION SHARING AND DISCLOSURE\n\nWe do not sell, trade, or otherwise transfer your personal information to third parties without your consent, except as described in this policy:\n\n• Service Providers: We may share information with third-party service providers who perform services on our behalf\n• Legal Requirements: We may disclose information if required by law or in response to valid requests by public authorities\n• Business Transfers: Information may be transferred in connection with a merger, acquisition, or sale of assets\n\n4. DATA SECURITY\n\nWe implement appropriate technical and organizational measures to protect your personal information against unauthorized access, alteration, disclosure, or destruction.\n\n• Encryption: We use industry-standard encryption to protect data in transit and at rest\n• Access Controls: We limit access to personal information to authorized personnel only\n• Regular Audits: We regularly review our security practices and update them as necessary\n\n5. DATA RETENTION\n\nWe retain your personal information for as long as necessary to provide our services and fulfill the purposes outlined in this policy, unless a longer retention period is required by law.\n\n6. YOUR RIGHTS\n\nDepending on your location, you may have certain rights regarding your personal information:\n\n• Access: Request access to your personal information\n• Correction: Request correction of inaccurate information\n• Deletion: Request deletion of your personal information\n• Portability: Request a copy of your information in a structured format\n• Objection: Object to certain processing of your information\n\n7. CHILDREN'S PRIVACY\n\nOur services are not intended for children under 13 years of age. We do not knowingly collect personal information from children under 13.\n\n8. INTERNATIONAL DATA TRANSFERS\n\nYour information may be transferred to and processed in countries other than your own. We ensure appropriate safeguards are in place for such transfers.\n\n9. CHANGES TO THIS POLICY\n\nWe may update this privacy policy from time to time. We will notify you of any changes by posting the new policy on this page and updating the \"Last updated\" date.\n\n10. CONTACT US\n\nIf you have any questions about this privacy policy, please contact us at:\n\nEmail: privacy@snapcad.com\nAddress: SnapCAD Privacy Team\n123 Technology Drive\nSan Francisco, CA 94105\nUnited States\n\nBy using our services, you acknowledge that you have read and understood this privacy policy and agree to the collection, use, and disclosure of your information as described herein.";
    
    self.contentLabel.text = privacyPolicy;
}

#pragma mark - Button Actions

- (void)backButtonTapped {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
